<template>
  <div class="answer-item">
    <div class="answer-item-title" @click="jumpDateils">
      {{ questionData.content.question_title }}
    </div>
    <div v-if="questionData.answer" class="answer-wrap">
      <div class="answer-wrap-left">
        <div v-if="questionData.answer && questionData.answer.user" class="answer-item-user">
          <div :style="{background:'url('+questionData.answer.user.user_photo+') center center no-repeat',backgroundSize:'100% 100%'}" class="answer-item-user-photo" @click="jumpToDoctor(questionData.answer.user.user_id)" />
          <div class="answer-item-user-name" @click="jumpToDoctor(questionData.answer.user.user_id)">
            {{ questionData.answer.user.user_name }}
          </div>
          <img v-if="questionData.answer.user.user_type === 'doctor'" src="~assets/img/doctor.png" alt="" class="answer-item-user-doctor" @click="jumpToDoctor(questionData.answer.user.user_id)">
          <div v-if="questionData.answer.user.user_type === 'doctor'" class="answer-item-user-position" @click="jumpToDoctor(questionData.answer.user.user_id)">
            {{ questionData.answer.user.user_attributes && questionData.answer.user.user_attributes.doctor_title ? questionData.answer.user.user_attributes.doctor_title + '｜': '' }}{{ questionData.answer.user.user_attributes && questionData.answer.user.user_attributes.hospital_name }}
          </div>
          <ul v-if="questionData.topic && questionData.topic.length > 0" class="good-at">
            <li v-for="item in questionData.topic" :key="item.id" @click="newTopic(item)">
              <img src="~assets/img/topic-icon.png" alt="">
              <span>{{ item.topic_name }}</span>
            </li>
          </ul>
        </div>
        <div class="answer-item-content">
          <div v-if="questionData.answer!=null" class="answer-item-content-box">
            <div class="answer-item-content-icon" />
            <div class="answer-item-content-text" @click="jumpDateils">
              {{ questionData.answer.answer_content_brief }}
            </div>
          </div>
          <div class="answer-item-num">
            <div class="answer-item-browse">
              {{ questionData.browse_count }}人已经看
            </div>
          </div>
        </div>
      </div>
      <div v-if="questionData.answer.images && questionData.answer.images.length > 0" class="answer-wrap-right">
        <img :src="questionData.answer.images[0].thumbnail_url" alt="加载错误">
      </div>
    </div>
  </div>
</template>
<script>
export default {
  components: {

  },
  props: {
    questionData: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {

    }
  },
  computed: {

  },
  created() {

  },
  mounted() {

  },
  methods: {
    jumpDateils() {
      this.$router.push(`/question/${this.questionData.content_id}`)
    },
    newTopic(item) {
      this.$emit('classId', { id: item.topic_id, name: item.topic_name })
    },
    jumpToDoctor(id) {
      this.$router.push(`/doctor/${id}`)
    }
  }
}
</script>
<style scoped lang="scss">
.answer-item {
  padding: 20px 0;
}
.answer-wrap {
  display: flex;
  .answer-wrap-left {
    flex: 1;
  }
  .answer-wrap-right {
    flex-shrink: 0;
    width: 156px;
    height: 120px;
    border-radius: 6px;
    overflow: hidden;
    border-radius: 6px;
    img {
      display: block;
      width: 156px;
      height: 120px;
      object-fit: cover;
    }
  }
}
.answer-item-title {
  font-size: 18px;
  font-weight: 500;
  color: #333;
  line-height: 25px;
  padding-bottom: 10px;
  cursor: pointer;
}
.answer-item-user {
  display: flex;
  align-items: center;
  margin-bottom: 14px;
  > div {
    cursor: pointer;
  }
  > img {
    cursor: pointer;
  }
  .answer-item-user-photo {
    width: 20px;
    height: 20px;
    border-radius: 50%;
  }
  .answer-item-user-name {
    font-size: 12px;
    color: rgba(102, 102, 102, 1);
    line-height: 17px;
    margin-left: 8px;
    font-weight: 500;
  }
  .answer-item-user-doctor{
    width: 52px;
    height: 20px;
    margin-left: 8px;
    object-fit: cover;
  }
  .answer-item-user-position{
    font-size: 12px;
    color: #666;
    margin-left: 8px;
  }
  .good-at {
    display: flex;
    list-style: none;
    margin: 0 0 0 8px;
    padding: 0;
    li {
      cursor: pointer;
      display: flex;
      align-items: center;
      height: 20px;
      line-height: 20px;
      padding: 0 8px;
      background: rgba(80, 76, 255, 0.06);
      border-radius: 10px;
      margin-left: 8px;
      img {
        height: 12px;
        width: 11px;
        margin-right: 5px;
      }
      span {
        font-size: 11px;
        color: #504CFF;
      }
    }
  }
  .answer-item-topic{
    font-size:12px;
    color:rgba(153,153,153,1);
    margin-left: 8px;
    display: flex;
  }
}
.answer-item-content {
  .answer-item-content-box {
    display: flex;
    margin-bottom: 28px;
    padding-right: 13px;
  }
  .answer-item-content-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    background: url("~assets/img/answer-icon.png") center center no-repeat;
    background-size: 100% 100%;
    margin-top: 2px;
  }
  .answer-item-content-text {
    height: 42px;
    margin-left: 10px;
    font-size: 14px;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
    line-height: 21px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    cursor: pointer;
  }
  .answer-item-num {
    display: flex;
    font-size: 12px;
    font-weight: 400;
    color: rgba(153, 153, 153, 1);
    line-height: 17px;
    padding: 0 24px;
  }
  .answer-item-comment{
    display: flex;
    margin-left: 23px;
    .answer-item-comment-icon{
      width: 14px;
      height: 14px;
      background: url('~assets/img/comment-icon.png') center center no-repeat;
      background-size: 100% 100%;
      margin-left: 10px;
    }
  }
  .answer-item-star{
    display: flex;
    margin-left: 23px;
    .answer-item-star-icon{
      width: 14px;
      height: 14px;
      background: url('~assets/img/star-icon.png') center center no-repeat;
      background-size: 100% 100%;
      margin-left: 10px;
    }
  }
}
</style>
